package net.gdface.sdk;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.Serializable;

/**
 * 
 * 人脸角度描述对象
 * @author guyadong
 *
 */
public class FAngle implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private	int   yaw;//angle of yaw,from -90 to +90,left is negative,right is postive
	private	int   pitch;//angle of pitch,from -90 to +90,up is negative,down is postive
	private	int   roll;//angle of roll,from -90 to +90,left is negative,right is postive
	private float confidence;//confidence of face pose(from 0 to 1,0.6 is suggested threshold)
	public FAngle() {
		this(0,0,0,0f);
	}
	public FAngle(int yaw, int pitch, int roll,float confidence) {
		this.yaw = yaw;
		this.pitch = pitch;
		this.roll = roll;
		this.confidence=confidence;
	}
	/**
	 * @return yaw
	 */
	public int getYaw() {
		return yaw;
	}
	/**
	 * @param yaw 要设置的 yaw
	 */
	public void setYaw(int yaw) {
		this.yaw = yaw;
	}
	/**
	 * @return pitch
	 */
	public int getPitch() {
		return pitch;
	}
	/**
	 * @param pitch 要设置的 pitch
	 */
	public void setPitch(int pitch) {
		this.pitch = pitch;
	}
	/**
	 * @return roll
	 */
	public int getRoll() {
		return roll;
	}
	/**
	 * @param roll 要设置的 roll
	 */
	public void setRoll(int roll) {
		this.roll = roll;
	}
	/**
	 * @return confidence
	 */
	public float getConfidence() {
		return confidence;
	}
	/**
	 * @param confidence 要设置的 confidence
	 */
	public void setConfidence(float confidence) {
		this.confidence = confidence;
	}
	@Override
	public String toString() {
		ByteArrayOutputStream bo = new ByteArrayOutputStream();
		toStream(new PrintStream(bo));
		return bo.toString();
	}
	/**
	 * 以文本形式向{@link PrintStream}输出对象内容 
	 * @param stream
	 */
	public void toStream(PrintStream stream) {
		stream.printf("[yaw=%d,picth=%d,roll=%d,confidence=%f]",this.yaw,this.pitch,this.roll,this.confidence);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(confidence);
		result = prime * result + pitch;
		result = prime * result + roll;
		result = prime * result + yaw;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof FAngle)) {
			return false;
		}
		FAngle other = (FAngle) obj;
		if (Float.floatToIntBits(confidence) != Float.floatToIntBits(other.confidence)) {
			return false;
		}
		if (pitch != other.pitch) {
			return false;
		}
		if (roll != other.roll) {
			return false;
		}
		if (yaw != other.yaw) {
			return false;
		}
		return true;
	}
}
